package com.sxkiler.demo.seata.controller;

import com.sxkiler.demo.seata.service.saga.SAGAProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/product/saga")
public class SAGAProductController {

    @Autowired
    SAGAProductService productService;

    @RequestMapping("/reduceStock")
    Boolean reduceStock(@RequestParam("productId") Long productId, @RequestParam("count") Integer count) throws Exception {
        return productService.reduceStock(productId, count);
    }

    @RequestMapping("/compensateStock")
    Boolean compensateStock(@RequestParam("productId") Long productId, @RequestParam("count") Integer count) throws Exception {
        return productService.compensateStock(productId, count);
    }

    @GetMapping("/getPrice")
    Integer getPrice(@RequestParam("productId") Long productId) {
        return productService.getPriceById(productId);
    }

}
